<?php
/**代理查询**/
namespace app\common\logic;
use think\Model;
use think\Db;
class Daili extends Model
{
	protected function initialize()
	{
		parent::initialize();
	}


	//取【代理团队】/人数/充值/提现/投注/优惠彩金/按照月份取
	public function  daili_rencont($daili,$times)
	{
		 $open_over=explode("|",$times);
		 	 
		 $dllist=Db::name('username')->where("tjr='{$daili}'")->select();

		 $XXRCOUNT = 0;
		 $DL_ZCZJE = 0; //注册金额
		 $DL_ZTXJE = 0; //提现金额
		 $DL_ZTZJE = 0; //
		 $DL_ZYHJE = 0;
		 $DL_REGS =0; 
		 $DLSHUJS = 0;
		 $DL_ZZJJE = 0;

		 foreach($dllist as $ls)
		 {
		 	$XXRCOUNT=$XXRCOUNT+1;

		 	//充值
		 	$chongzhi = Db::name('chongzhi_list')->where("username='".$ls['username']."' AND cztime>$open_over[0] AND cztime<$open_over[1] AND zt=1")->field('je')->select();
		 	foreach($chongzhi as $cz){ $DL_ZCZJE=$DL_ZCZJE+$cz['je'];}

		 	//提现
		 	$tixian = Db::name('tixian_list')->where("username='".$ls['username']."' AND txtime>$open_over[0] AND txtime<$open_over[1] AND zt=1")->field('txje')->select();

		 	foreach($tixian as $tx){ $DL_ZTXJE=$DL_ZTXJE+$tx['txje'];}

		 	//投注
		 	$touzhu = Db::name('touzhu_list_ok')->where("username='".$ls['username']."' AND tz_time>$open_over[0] AND tz_time<$open_over[1] AND ifqs=1")->select();

		 	foreach($touzhu as $tz){ $DL_ZTZJE=$DL_ZTZJE+$tz['tzje'];$DL_ZZJJE=$DL_ZZJJE+$tz['zjje'];}

		 	//优惠彩金
		 	$yhcaij = Db::name('caijin_list')->where("username='".$ls['username']."' AND fstime>$open_over[0] AND fstime<$open_over[1]")->field('cjje')->select();
		 	foreach($yhcaij as $yh){$DL_ZYHJE=$DL_ZYHJE+$yh['cjje'];}

		 	//月注册人数
		 	$regs = Db::name('username')->where("tjr='{$daili}' AND reg_time>$open_over[0] AND reg_time<$open_over[1]")->field('id')->select();
		 	foreach($regs as $rg){$DL_REGS=$DL_REGS+1;}


		 }
		 
		 $DL_YKJE=$DL_ZTZJE-$DL_ZZJJE;

		 $DLSHUJS=array(
		 	'1' => $XXRCOUNT,
		 	'2' => $DL_ZCZJE,
		 	'3' => $DL_ZTXJE,
		 	'4' => $DL_ZTZJE,
		 	'5' => $DL_ZYHJE,
		 	'6' => $DL_REGS,
		 	'7' => $DL_YKJE,
		 );

		 return $DLSHUJS; 
	}


	//取会员/充值/提现/投注/优惠彩金/按照月份取
	public function user_rencont($user,$times)
	{	 
		 $open_over=explode("|",$times);

		 $DL_ZCZJE=$DL_ZTXJE=$DL_ZTZJE=$DL_ZYHJE=$DL_ZZJJE=0;
		 
		 //充值
		 $chongzhi = Db::name('chongzhi_list')->where("username='".$user."' AND cztime>$open_over[0] AND cztime<$open_over[1] AND zt=1")->field('je')->select();
		 foreach($chongzhi as $cz){ $DL_ZCZJE=$DL_ZCZJE+$cz['je'];}

		 //提现
	 	 $tixian = Db::name('tixian_list')->where("username='".$user."' AND txtime>$open_over[0] AND txtime<$open_over[1] AND zt=1")->field('txje')->select();

	 	 foreach($tixian as $tx){ $DL_ZTXJE=$DL_ZTXJE+$tx['txje'];}
 
		 //投注
	 	 $touzhu = Db::name('touzhu_list_ok')->where("username='".$user."' AND tz_time>$open_over[0] AND tz_time<$open_over[1] AND ifqs=1")->select();

	 	 foreach($touzhu as $tz){ $DL_ZTZJE=$DL_ZTZJE+$tz['tzje'];$DL_ZZJJE=$DL_ZZJJE+$tz['zjje'];}
		 
		 //优惠彩金
	 	 $yhcaij = Db::name('caijin_list')->where("username='".$user."' AND fstime>$open_over[0] AND fstime<$open_over[1]")->field('cjje')->select();

		 foreach($yhcaij as $yh){$DL_ZYHJE=$DL_ZYHJE+$yh['cjje'];}

		 
		 $DL_YKJE=$DL_ZTZJE-$DL_ZZJJE;
		 
		 $DLSHUJS=array(
		 	'1' => $DL_ZCZJE,
		 	'2' => $DL_ZTXJE,
		 	'3' => $DL_ZTZJE,
		 	'4' => $DL_ZYHJE,
		 	'5' => $DL_YKJE,
		 );
		 return $DLSHUJS;	 
	}
	
}